package com.drug.mingkang.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * 描述：swagger配置
 *
 * @version 1.0
 * @author: wcj
 * @Date: 2020/5/17 18:23
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket docket1(){
        return  new Docket(DocumentationType.SWAGGER_2).groupName("小小");
    }
    @Bean
    public Docket docket2(){
        return  new Docket(DocumentationType.SWAGGER_2).groupName("A");
    }
    @Bean
    public Docket docket3(){
        return  new Docket(DocumentationType.SWAGGER_2).groupName("B");
    }
    @Bean
    public Docket docket4(){
        return  new Docket(DocumentationType.SWAGGER_2).groupName("C").apiInfo(this.apiInfo()).select().apis(RequestHandlerSelectors.basePackage("")).build();
    }


    //配置Swagger的Docket的Bean实例
    //enable是否启动Swagger，如果为false，则不能在浏览器中访问
    @Bean
    public Docket docket(Environment environment){
        //设置要显示的Swagger环境
        Profiles profiles = Profiles.of("dev","test");

        //获取项目环境：
        //通过environment.acceptsProfiles判断是否处在自己设定的环境当中
        boolean flag = environment.acceptsProfiles(profiles);

        System.out.println("flag = " + flag);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("hello")
                .enable(flag)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.drug.mingkang"))
                .build();
    }

    //配置swagger信息=apiInfo
    private ApiInfo apiInfo(){
        //作者信息
        Contact contact = new Contact("", "http://192.168.1.198:10070/platformgroup/ms-admin", "2357248777@qq.com");
        return new ApiInfo("明康医药",
                "服务:发布为进销存管理系统",
                "1.0",
                "http://192.168.1.198:10070/platformgroup/ms-admin",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
